package com.accompany.service.impl;

import com.accompany.entity.MasterTag;
import com.accompany.dao.MasterTagMapper;
import com.accompany.service.MasterTagService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 大神-标签关联表 服务实现类
 * </p>
 *
 * @author DC
 * @since 2024-12-26
 */
@Slf4j
@Service
public class MasterTagServiceImpl extends ServiceImpl<MasterTagMapper, MasterTag> implements MasterTagService {

    @Autowired
    private MasterTagMapper masterTagMapper;

    /**
     * 分页查询大神-标签关联列表
     *
     * @param page 页码
     * @param size 每页大小
     * @return 分页结果
     */
    @Override
    public Page<MasterTag> getPaginatedMasterTags(Integer page, Integer size) {
        try {
            log.info("分页查询大神-标签关联列表，页码：{}, 每页大小：{}", page, size);
            Page<MasterTag> pageObj = new Page<>(page, size);
            Page<MasterTag> masterTagPage = masterTagMapper.selectPage(pageObj, null);
            masterTagPage.getRecords().forEach(item -> log.info(item.toString()));
            return masterTagPage;
        } catch (Exception e) {
            log.error("分页查询大神-标签关联列表时发生错误，页码：{}, 每页大小：{}", page, size, e);
            throw e;
        }
    }

    /**
     * 获取所有大神-标签关联列表
     *
     * @return 大神-标签关联列表
     */
    @Override
    public List<MasterTag> getAllMasterTags() {
        try {
            log.info("获取所有大神-标签关联列表");
            return masterTagMapper.selectList(null);
        } catch (Exception e) {
            log.error("获取所有大神-标签关联列表时发生错误", e);
            throw e;
        }
    }

    /**
     * 获取单个大神-标签关联信息
     *
     * @param id 大神-标签关联ID
     * @return 大神-标签关联对象
     */
    @Override
    public MasterTag getMasterTagById(Long id) {
        try {
            log.info("获取单个大神-标签关联信息，大神-标签关联ID：{}", id);
            return masterTagMapper.selectById(id);
        } catch (Exception e) {
            log.error("获取单个大神-标签关联信息时发生错误，大神-标签关联ID：{}", id, e);
            throw e;
        }
    }

    /**
     * 更新大神-标签关联信息
     *
     * @param masterTag 大神-标签关联信息
     */
    @Override
    @Transactional
    public void updateMasterTag(MasterTag masterTag) {
        try {
            log.info("更新大神-标签关联信息，大神-标签关联信息：{}", masterTag.toString());
            masterTagMapper.updateById(masterTag);
        } catch (Exception e) {
            log.error("更新大神-标签关联信息时发生错误，大神-标签关联信息：{}", masterTag.toString(), e);
            throw e;
        }
    }

    /**
     * 删除大神-标签关联
     *
     * @param id 大神-标签关联ID
     */
    @Override
    @Transactional
    public void deleteMasterTag(Long id) {
        try {
            log.info("删除大神-标签关联，大神-标签关联ID：{}", id);
            masterTagMapper.deleteById(id);
        } catch (Exception e) {
            log.error("删除大神-标签关联时发生错误，大神-标签关联ID：{}", id, e);
            throw e;
        }
    }

    /**
     * 创建大神-标签关联
     *
     * @param masterTag 大神-标签关联信息
     */
    @Override
    @Transactional
    public void createMasterTag(MasterTag masterTag) {
        try {
            log.info("创建大神-标签关联：{}", masterTag.toString());
            masterTagMapper.insert(masterTag);
        } catch (Exception e) {
            log.error("创建大神-标签关联时发生错误，大神-标签关联信息：{}", masterTag.toString(), e);
            throw e;
        }
    }
}